/***************************************************************************
 *   This is a part of the NextCAD Web APP.                                *
 *   Copyright (C) AMCAX, All rights reserved.                             *
 ***************************************************************************/
import { BaseCommand } from '@amcax/base';

import i18n from 'i18next';
import { useEffect, useRef } from 'react';

import CmdInteractor from './CmdInteractor';
import { ArcCommandProps } from './types';
import CmdThreePointArc from './three-point-arc';

function ArcCommand({ onClose }: ArcCommandProps) {
  const cmdRef = useRef<CmdInteractor>(null);
  useEffect(() => {
    cmdRef.current = new CmdInteractor();
    cmdRef.current.addExit(onClose);
    return () => {
      cmdRef.current?.destroy();
      cmdRef.current = null;
    };
  }, []);
  return <></>;
}

export const cmdArc: BaseCommand = {
  id: 'CmdArc',
  label: 'command.arc',
  icon: 'commands/sketch/center-arc',
  group: 'sketch',
  create: function (label: string, onClose: () => void) {
    return (
      <ArcCommand
        title={i18n.t(label)}
        onClose={onClose}
      />
    );
  },
};
function ThreePointArcCommand({ onClose }: ArcCommandProps) {
  const cmdRef = useRef<CmdThreePointArc>(null);
  useEffect(() => {
    cmdRef.current = new CmdThreePointArc();
    cmdRef.current.addExit(onClose);
    return () => {
      cmdRef.current?.destroy();
      cmdRef.current = null;
    };
  }, []);
  return <></>;
}
export const cmdThreePointArc: BaseCommand = {
  id: 'CmdThreePointArc',
  label: 'command.three-point-arc',
  icon: 'commands/sketch/three-point-arc',
  group: 'sketch',
  create: function (label: string, onClose: () => void) {
    return (
      <ThreePointArcCommand
        title={i18n.t(label)}
        onClose={onClose}
      />
    );
  },
};
